package com.store.framework.db;

import java.util.ArrayList;
import java.util.List;

import javax.sql.rowset.CachedRowSet;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.store.framework.dao.IAppRootListDao;
import com.store.framework.entry.RootList;

public class AppRootListDao implements IAppRootListDao {
	private static Log LOG = LogFactory.getLog(AppRootListDao.class);

	@Override
	public int AddRootList(RootList rt) {
		int ar = 0;
		String sql = "insert into app_rootlist(Id,,RootName,RootCode,Domain,Url,Param,Type,"
				+ "RootId,Self,SAddDate,SaddPer,EditDate,EditPer,DelDate,DelPer,Del"
				+ ",Remarks) value(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
		try {
			DaoUtil.executeUpdate(sql, rt.getId(), rt.getRootName(),
					rt.getRootCode(), rt.getDomain(), rt.getUrl(),
					rt.getParam(), rt.getType(), rt.getRootId(), rt.getSelf(),
					rt.getAddDate(), rt.getAddPer(), rt.getEditDate(),
					rt.getEditPer(), rt.getDelDate(), rt.getDelPer(),
					rt.getDel(), rt.getRemarks());
			ar = 1;
		} catch (Exception e) {
			ar = 0;
			LOG.error(e.getMessage(),e);
			throw new RuntimeException(e.getMessage(),e);
		}
		return ar;
	}

	@Override
	public List<RootList> selectRootList() {
		List<RootList> list = new ArrayList<RootList>();
		RootList rl = new RootList();
		String sql = "select *from app_rootlist";
		try {
			CachedRowSet crs = DaoUtil.SimpleQuery(sql);
			while (crs.next()) {
				rl.setId(crs.getString("Id"));
				rl.setRootName(crs.getString("RootName"));
				rl.setRootCode(crs.getString("RootCode"));
				rl.setDomain(crs.getString("Domain"));
				rl.setUrl(crs.getString("Url"));
				rl.setParam(crs.getString("Param"));
				rl.setType(crs.getString("Type"));
				rl.setRootId(crs.getString("RootId"));
				rl.setSelf(crs.getString("Self"));
				rl.setAddDate(crs.getDate("SAddDate"));
				rl.setAddPer(crs.getString("SaddPer"));
				rl.setEditDate(crs.getDate("EditDate"));
				rl.setEditPer(crs.getString("EditPer"));
				rl.setDelDate(crs.getDate("DelDate"));
				rl.setDelPer(crs.getString("DelPer"));
				rl.setDel(crs.getByte("Del"));
				rl.setRemarks(crs.getString("Remarks"));
				list.add(rl);

			}
		} catch (Exception e) {
			list = null;
			LOG.error(e.getMessage(),e);
			throw new RuntimeException(e.getMessage(),e);
		}
		return list;
	}

}
